<template>
	<view>
		<!-- 顶部 -->
		<view class="center a-center j-sp pad-t-40 pad-b-40">
			<view>
				<view class="a-center">
					<view class="logo border-r overflow-hidden"><image :src="adminSet.logo" mode="widthFix" lazy-load></image></view>
					<view class="font-28 black20-zt mar-left20">{{content.author}}</view>
				</view>
				<view class="a-center mar-top15">
					<view class="font-24 black60-zt">{{content.createtime|timeStanp}}</view>
					<view class="font-24 black60-zt mar-left20"> 阅读量：{{processing(content.readcount)}}</view>
				</view>
			</view>
			<view class="cate_name main-zt font-26 border-r-5 line-h50 pad-l-30 pad-r-30">{{cateList[0].name}}</view>
		</view>
		<!-- 内容 -->
		<view class="center mar-top30 pad-b-20 pad-t-30">
			<view class="center">
				<rich-text :nodes="content.content"></rich-text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:undefined,
				content:{},
				adminSet:{},
				cateList:[]
			}
		},
		onLoad(e) {
			this.id=parseFloat(e.id)
			this.getNewsShow()
			this.GetAdmin()
			this.AddYue()
			//开启分享
			wx.showShareMenu({
				withShareTicket:true,
				menus:["shareAppMessage","shareTimeline"]
			})
		},
		filters:{
			timeStanp(dataTime){
				if (dataTime === undefined) { return }
				  const time = dataTime
				  const unixTimestamp = new Date(time * 1000)
				  const commonTime = unixTimestamp.toLocaleString('en-GB', { hour12: false })
				  const tim = commonTime.split('/')
				  const year = tim[2].split(',')[0]
				  const month = tim[1]
				  const day = tim[0]
				  const tt = tim[2].split(',')[1]
				  if (time === '') {
				    return ''
				  } else {
				    return year + '/' + month + '/' + day + tt
				  }
			}
		},
		//设置分享好友的内容
		onShareAppMessage(res) {
			if (res.from=="button"){
				console.log(res.target)
			}
			return {
				title:"鑫意到家",
				path: '/pagesC/news/news?id='+this.id,
				desc:"鑫意到家 · 洁新留下！",
				imageUrl:"../../static/202310131154405365.png"
			}
		},
		//分享朋友圈
		onShareTimeline(res) {
			return {
				title: '鑫意到家 · 洁新留下！',
				type: 0,
				summary: "鑫意到家 · 洁新留下！",
			}
		},
		methods: {
			//阅读+
			async AddYue(){
				const one={
					id:this.id
				}
				this.$api.AddYuedu(one).then(res=>{
					
				})
			},
			//数字处理
			processing(e){
				if(e>10000){
					const sum=Math.floor((e/10000)*100)/100
					return sum+'w'
				}else {
					return e
				}
			},
			//获取系统基本信息
			async GetAdmin(){
				const one={
					id:1
				}
				await this.$api.GetAdminSet(one).then(res=>{
					this.adminSet=res.data.list
				})
			},
			//设置标题
			navTitle(str) {
				uni.setNavigationBarTitle({
					title: str
				})
			},
			//获取文章内容
			async getNewsShow(){
				const one={
					id:this.id
				}
				await this.$api.GetArticleShow(one).then(res=>{
					res.data.content = res.data.content.replace(/<img/gi, "<img class='richImg'");
					this.content=res.data
					this.navTitle(res.data.name)
					this.GetArticleList(res.data.cid)
				})
			},
			//获取文章list
			async GetArticleList(e){
				const two={
					aid:1,
					id:e
				}
				await this.$api.GetArticleCategoryList(two).then(res=>{
					this.cateList=res.data.list
				})
			}
		}
	}
</script>

<style lang="scss">
	body{
	    background-color: #ffffff;  
	} 
	.richImg {
	    width: 100% !important;
	    height: auto !important;
	}
	image{
		width: 100%;
		display: block;
	}
	.logo{
		width: 80rpx;
		height: 80rpx;
	}
	.cate_name{
		border: 2rpx solid #7ab13d;
	}
</style>
